﻿#region Opis pliku
//-----------------------------------------------------------------------------
// Entity.cs
// Autor: Jan Fraś
// 30.10.2012
//-----------------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace pogra
{

    /// <summary>
    /// klasa wszelkich obiektów strony konfliktu ( budynki, jednostki )
    /// zawiera podstawowe pola takie jak pozycja i ustawienie kątowe, oraz identyfikator strony konfliktu
    /// </summary>
    public abstract class Entity
    {
        #region pola

        protected Vector2 position;
        protected float rotation;
        protected int team;
        protected List<Unit> enemyteam;
        protected int lifetime = 0;
        protected int hp;
        protected int maxhp;
        protected ParticleSystem particleSystem = new ParticleSystem();
        protected Texture2D particletexture;
        protected Color color;
        #endregion

        #region inicjalizacja
        public Entity(Vector2 pos, float rotation, int team, List<Unit> enemyteam)
        {
            color = Color.White;
            this.position = pos;
            this.rotation = rotation;
            this.team = team;
            this.enemyteam = enemyteam;
        }
        #endregion

        #region metody draw i update
        virtual public bool Update(TimeSpan time)
        {
            lifetime += time.Milliseconds;
            particleSystem.Update(time);
            return true;
        }

        virtual public void Draw(ExtendedSpriteBatch exSpriteBatch)
        {
            particleSystem.Draw(exSpriteBatch);

            if (Health > 0)
            {
                int width = 30;
                int height = 10;
                int length = (int)(width * ((float)hp / (float)maxhp));
                exSpriteBatch.FillRectangle(new Rectangle((int)(position.X - width / 2), (int)(position.Y - height), length, 3), Color.Chartreuse);
                exSpriteBatch.FillRectangle(new Rectangle((int)(position.X - width / 2 + length), (int)(position.Y - height), width - length, 3), Color.Red);
            }
            else
                color = Color.Black*0.3f;
        }
        #endregion

        #region logika różna

        /// <summary>
        /// metoda odpowaidająca za przyjmowanie obrażeń przez jednostkę
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="attackrotation"></param>
        /// <returns></returns>
        virtual public int takehit(int hit, float attackrotation)
        {
            int tmp = (int)((float)hit * ((float)Rand.next() / 100f));
            hp -= tmp;
            return tmp;
        }
        #endregion

        #region właściwości
        public int Team
        {
            get{return team;}
            set { }
        }

        public Vector2 Position
        {
            get { return position; }
        }

        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }
        
        public int Health 
        {
            get{return hp;}  
        }

        /// <summary>
        /// zdrowie maxymalne (czyli początkowe)
        /// </summary>
        public int MaxHealth
        {
            get { return maxhp; }
        }

        #endregion

    }
}
